package com.meituan.mapper;

import com.meituan.model.GoodsClassifyEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface GoodsClassifyMapper {
    @Select("select * from goods_classify where shop_id = #{shopId}")
    @Results({
            @Result(property = "goodsList",column = "classify_id",
            one = @One(select = "com.meituan.mapper.GoodsMapper.findByClassifyId",fetchType = FetchType.EAGER))
    })
    List<GoodsClassifyEntity> findByShopIdWithGoods(String shopId);

    @Select("select * from goods_classify where shop_id = #{shopId}")
    List<GoodsClassifyEntity> findByShopId(String shopId);
    @Select("select * from goods_classify where classify_id = #{classifyId}")
    GoodsClassifyEntity findById (String classifyId);
    @Insert("insert into goods_classify(shop_id,classify_name) values (#{shopId},#{classifyName})")
    Integer save(GoodsClassifyEntity goodsClassifyEntity);
    @Delete("delete from goods_classify where classify_id = #{classifyId}")
    Integer delete(String classifyId);

    @Update("update goods_classify set classify_name = #{classifyName} where classify_id = #{classifyId}")
    Integer updateClassifyName(@Param("classifyName")String classifyName,@Param("classifyId") String classifyId);
}
